package cn.kent;

import java.util.HashMap;
import java.util.Map;

public class TitleToNumber {

    public static int titleToNumber2(String columnTitle) {
        int number = 0;
        int multiple = 1;
        for (int i = columnTitle.length() - 1; i >= 0; i--) {
            int k = columnTitle.charAt(i) - 'A' + 1;
            number += k * multiple;
            multiple *= 26;
        }
        return number;
    }


    /**
     * 输入: columnTitle = "ZY"
     * 输出: 701
     * <p>
     * 输入: columnTitle = "FXSHRXW"
     * 输出: 2147483647
     * <p>
     * 来源：力扣（LeetCode）
     * 链接：https://leetcode-cn.com/problems/excel-sheet-column-number
     * 著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。
     */
    public static int titleToNumber(String columnTitle) {

        int length = columnTitle.length(); // 数字总位数
        int res = 0;
        for (int i = 0; i < columnTitle.length(); i++) {
            // 首位 = chars.length
            res += (columnTitle.charAt(i)-'A'+1) * Math.pow(26, length - 1);
            length--;
        }
        return res;
    }

    public static void main(String[] args) {
        String columnTitle = "FXSHRXW";
        int i = titleToNumber(columnTitle);
        System.out.println(i);

        System.out.println(Integer.MAX_VALUE);
    }
}
